package annotion.example.hss_fst.baselib;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.daimajia.slider.library.Animations.DescriptionAnimation;
import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.TextSliderView;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
//import com.hss.common.utils.log.LogUtils;
import com.meetme.android.multistateview.MultiStateView;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @Bind(R.id.pull_refresh_list)
    PullToRefreshListView pullRefreshList;
    @Bind(R.id.msv)
    MultiStateView msv;
    @Bind(R.id.btn_showcontent)
    Button btnShowcontent;
    @Bind(R.id.btn_showneterr)
    Button btnShowneterr;
    @Bind(R.id.btn_showloading)
    Button btnShowloading;
    @Bind(R.id.btn_showgeneral)
    Button btnShowgeneral;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initParams();
        initView();
        initListener();

//        LogUtils.e("zhangsan ");
    }
    ArrayAdapter arrayAdapter;
    String[] array= {"a","b","c","d"};
    void initParams() {
         arrayAdapter = new ArrayAdapter(
                 MainActivity.this, android.R.layout.simple_list_item_1,
                 array);

    }

    void initView() {
        SliderLayout banner =(SliderLayout) LayoutInflater.from(this).inflate(R.layout.banner,null);
        banner.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, 200));
        pullRefreshList.getRefreshableView().addHeaderView(banner);
        pullRefreshList.getRefreshableView().setAdapter(arrayAdapter);
        HashMap<String,String> url_maps = new HashMap<String, String>();
        url_maps.put("Hannibal", "http://static2.hypable.com/wp-content/uploads/2013/12/hannibal-season-2-release-date.jpg");
        url_maps.put("Big Bang Theory", "http://tvfiles.alphacoders.com/100/hdclearart-10.png");
        url_maps.put("House of Cards", "http://cdn3.nflximg.net/images/3093/2043093.jpg");
        url_maps.put("Game of Thrones", "http://images.boomsbeat.com/data/images/full/19640/game-of-thrones-season-4-jpg.jpg");
        for(String name : url_maps.keySet()){
            TextSliderView textSliderView = new TextSliderView(this);
            // initialize a SliderLayout
            textSliderView
                    .description(name)
                    .image(url_maps.get(name))
                    .setScaleType(BaseSliderView.ScaleType.Fit);
//                    .setOnSliderClickListener(this);

            //add your extra information
            textSliderView.bundle(new Bundle());
            textSliderView.getBundle()
                    .putString("extra",name);

            banner.addSlider(textSliderView);
        }

        banner.setPresetTransformer(SliderLayout.Transformer.Accordion);
        banner.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
        banner.setCustomAnimation(new DescriptionAnimation());
        banner.setDuration(4000);
    }

    void initListener() {
        pullRefreshList.setOnRefreshListener(refreshListener2);
    }

    @OnClick({R.id.btn_showcontent, R.id.btn_showneterr, R.id.btn_showloading, R.id.btn_showgeneral})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_showcontent:
                msv.setState(MultiStateView.ContentState.CONTENT);
                break;
            case R.id.btn_showneterr:
                msv.setState(MultiStateView.ContentState.ERROR_NETWORK);

                break;
            case R.id.btn_showloading:
                msv.setState(MultiStateView.ContentState.LOADING);

                break;
            case R.id.btn_showgeneral:
//                msv.setState(MultiStateView.ContentState.ERROR_GENERAL);

                break;
        }
    }

    PullToRefreshBase.OnRefreshListener2<ListView> refreshListener2 = new PullToRefreshBase.OnRefreshListener2<ListView>() {
        @Override
        public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
            String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);

            // Update the LastUpdatedLabel
            refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
            refreshView.onRefreshComplete();

        }

        @Override
        public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
            String label = DateUtils.formatDateTime(getApplicationContext()
                            .getApplicationContext(), System.currentTimeMillis(),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE
                            | DateUtils.FORMAT_ABBREV_ALL);
            // Update the LastUpdatedLabel
            refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
            refreshView.onRefreshComplete();
        }
    };
//    mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
//        @Override
//        public void onRefresh(PullToRefreshBase<ListView> refreshView) {
//            String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
//                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
//
//            // Update the LastUpdatedLabel
//            refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
//
//            // Do work to refresh the list here.
//            new GetDataTask().execute();
//        }
//    });
//
//    // Add an end-of-list listener
//    mPullRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() {
//
//        @Override
//        public void onLastItemVisible() {
//            Toast.makeText(PullToRefreshListActivity.this, "End of List!", Toast.LENGTH_SHORT).show();
//        }
//    });
//
//    ListView actualListView = mPullRefreshListView.getRefreshableView();





}
